package cn.bgs.service.impl;

import cn.bgs.common.R;
import cn.bgs.pojo.InvestmentProcess;
import cn.bgs.mapper.InvestmentProcessMapper;
import cn.bgs.service.InvestmentProcessService;
import cn.bgs.vo.RandomUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 招商流程表 服务实现类
 * </p>
 *
 * @author Mr.Zhao
 * @since 2022-08-08
 */
@Service
public class InvestmentProcessServiceImpl extends ServiceImpl<InvestmentProcessMapper, InvestmentProcess> implements InvestmentProcessService {

    @Autowired
    private InvestmentProcessMapper investmentProcessMapper;

    @Override
    public R findInvestmentProcess(String inProInfo, String inProCompany) {

        List<InvestmentProcess> investmentProcessList = investmentProcessMapper.findInvestmentProcess(inProInfo,inProCompany);

        return R.ok().data("investmentProcessList",investmentProcessList);
    }

    @Override
    public R findInvestmentProcessId(Integer id) {

        InvestmentProcess investmentProcess = investmentProcessMapper.findInvestmentProcessId(id);

        return R.ok().data("investmentProcess",investmentProcess);
    }

    @Override
    public R delInvestmentProcess(Integer id) {

        InvestmentProcess investmentProcess = investmentProcessMapper.findInvestmentProcessId(id);

        investmentProcess.setDeleteFlag(1);

        Integer i = investmentProcessMapper.updateInvestmentProcess(investmentProcess);

        if (i!=0){
            return R.ok();
        }else {
            return R.error().data("error","删除失败");
        }
    }

    @Override
    public R addInvestmentProcess(InvestmentProcess investmentProcess) {

        investmentProcess.setInProNumber(RandomUtil.getSixBitRandom());

        Integer i = investmentProcessMapper.addInvestmentProcess(investmentProcess);

        if (i!=0){
            return R.ok();
        }else {
            return R.error().data("error","新增失败");
        }
    }

    @Override
    public R updateInvestmentProcess(InvestmentProcess investmentProcess) {

        Integer i = investmentProcessMapper.updateInvestmentProcess(investmentProcess);

        if (i!=0){
            return R.ok();
        }else {
            return R.error().data("error","编辑失败");
        }
    }
}
